package com.alibaba.alink.common.lazy;

import org.apache.flink.ml.api.misc.param.ParamInfo;
import org.apache.flink.ml.api.misc.param.ParamInfoFactory;
import org.apache.flink.ml.api.misc.param.WithParams;

/**
 * An interface indicating lazy print of transform information can be enabled.
 * <p>
 * The enabled status is stored like parameters, while no actual lazy print is realized within this interface.
 * Right now, only {@link com.alibaba.alink.pipeline.TransformerBase} and
 * {@link com.alibaba.alink.pipeline.Trainer} is supported.
 * <p>
 * For a TransformerBase, when it transforms a BatchOperator, printing preview or statistics of its output is supported.
 * For a Trainer, the model generated by the call of `fit` inherit its settings.
 *
 * @param <T> the TransformerBase or Trainer class
 */
public interface HasLazyPrintTransformInfo<T> extends WithParams<T> {

    ParamInfo<Boolean> LAZY_PRINT_TRANSFORM_DATA_ENABLED = ParamInfoFactory
        .createParamInfo("lazyPrintTransformDataEnabled", Boolean.class)
        .setDescription("Enable lazyPrint of ModelInfo")
        .setHasDefaultValue(false)
        .build();

    ParamInfo<String> LAZY_PRINT_TRANSFORM_DATA_TITLE = ParamInfoFactory
        .createParamInfo("lazyPrintTransformDataTitle", String.class)
        .setDescription("Title of ModelInfo in lazyPrint")
        .setHasDefaultValue(null)
        .build();

    ParamInfo<Integer> LAZY_PRINT_TRANSFORM_DATA_NUM = ParamInfoFactory
        .createParamInfo("lazyPrintTransformDataNum", Integer.class)
        .setDescription("Title of ModelInfo in lazyPrint")
        .setHasDefaultValue(-1)
        .build();

    ParamInfo<Boolean> LAZY_PRINT_TRANSFORM_STAT_ENABLED = ParamInfoFactory
        .createParamInfo("lazyPrintTransformStatEnabled", Boolean.class)
        .setDescription("Enable lazyPrint of ModelInfo")
        .setHasDefaultValue(false)
        .build();

    ParamInfo<String> LAZY_PRINT_TRANSFORM_STAT_TITLE = ParamInfoFactory
        .createParamInfo("lazyPrintTransformStatTitle", String.class)
        .setDescription("Title of ModelInfo in lazyPrint")
        .setHasDefaultValue(null)
        .build();

    default T enableLazyPrintTransformData(int n, String title) {
        this.set(LAZY_PRINT_TRANSFORM_DATA_ENABLED, true);
        this.set(LAZY_PRINT_TRANSFORM_DATA_NUM, n);
        this.set(LAZY_PRINT_TRANSFORM_DATA_TITLE, title);
        return (T) this;
    }

    /**
     * Enable lazily printing of first n items of the transform data.
     *
     * @param n number of items.
     * @return the TransformerBase or Trainer instance itself.
     */
    default T enableLazyPrintTransformData(int n) {
        return enableLazyPrintTransformData(n, null);
    }

    /**
     * Enable lazily printing of the statistics of the transform data with a title.
     *
     * @param title title
     * @return the TransformerBase or Trainer instance itself.
     */
    default T enableLazyPrintTransformStat(String title) {
        this.set(LAZY_PRINT_TRANSFORM_STAT_ENABLED, true);
        this.set(LAZY_PRINT_TRANSFORM_STAT_TITLE, title);
        return (T) this;
    }

    /**
     * Enable lazily printing of the statistics of the transform data.
     *
     * @return the TransformerBase or Trainer instance itself.
     */
    default T enableLazyPrintTransformStat() {
        enableLazyPrintTransformStat(null);
        return (T) this;
    }
}
